# -*- coding: utf-8 -*-
from logger_setup import get_logger
import net_tool
import login
import yaml_tool

setting_logger = get_logger("setting_logger")
cfg = yaml_tool.get_dict()
net = cfg['net']
url2 = str(net['url'])

def reconnection():
    """重连"""
    if not net_tool.is_network_port_connected():
        setting_logger.warning("网络接口未连接，无法重连")
        return True
    url1 = 'https://www.baidu.com'
    if not net_tool.verify(url1):  # 判断是否联网
        if net_tool.verify(url2):  # 判断是否在校园网范围内
            login_message = login.login()
            if not login_message:
                return False
            else:
                return True
        else:
            return True
    else:
        return True